home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DJLGR106.ARJ / BLIT.CC < prev    next >
C/C++ Source or Header  |  1991-03-06  |  3KB  |  114 lines

  1. /* This is file BLIT.CC */
  2. /*
  3. ** Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. **
  5. ** This file is distributed under the terms listed in the document
  6. ** "copying.dj", available from DJ Delorie at the address above.
  7. ** A copy of "copying.dj" should accompany this file; if not, a copy
  8. ** should be available from where this file was obtained.  This file
  9. ** may not be distributed without a verbatim copy of "copying.dj".
  10. **
  11. ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  12. ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. */
  14.  
  15. #include <string.h>
  16. #include "graphics.h"
  17. #include <pc.h>
  18.  
  19. extern "C" int _GrCanBcopyInBlit;
  20.  
  21. void Blit(GrRegion *src,
  22.           GrRegion *dest, int dx, int dy,
  23.           GrBlitFunc function)
  24. {
  25.   Blit(src, 0, 0, src->width, src->height, dest, dx, dy, function);
  26. }
  27.  
  28. void Blit(GrRegion *src, int sx, int sy, int sw, int sh,
  29.           GrRegion *dest, int dx, int dy,
  30.           GrBlitFunc function)
  31. {
  32.   GrRegion *s = src->SubRegion(sx, sy, sw, sh);
  33.   if (!s)
  34.     return;
  35.   if (!(s->data))
  36.   {
  37.     delete s;
  38.     return;
  39.   }
  40.   GrRegion *d = dest->SubRegion(dx, dy, sw, sh);
  41.   if (!d)
  42.   {
  43.     delete s;
  44.     return;
  45.   }
  46.   if (!(d->data))
  47.   {
  48.     delete s;
  49.     delete d;
  50.     return;
  51.   }
  52.   if (s->width < d->width)
  53.     d->width = s->width;
  54.   else
  55.     s->width = d->width;
  56.   if (s->height < d->height)
  57.     d->height = s->height;
  58.   else
  59.     s->height = d->height;
  60.  
  61.   sw = s->width;
  62.   sh = s->height;
  63.  
  64.   int reverse=0;
  65.   if (s->data < d->data)
  66.     reverse = 1;
  67.   register int x,y;
  68.   char *temp_data = (char *)malloc(sw);
  69.   switch (function)
  70.   {
  71.     case BlitSrc:
  72.       if (reverse)
  73.       {
  74.         if (_GrCanBcopyInBlit)
  75.           for (y=sh-1; y>=0; y--)
  76.             bcopy(s->rdata+y*s->row_scale, d->wdata+y*d->row_scale, sw);
  77.         else
  78.           for (y=sh-1; y>=0; y--)
  79.           {
  80.             bcopy(s->rdata+y*s->row_scale, temp_data, sw);
  81.             bcopy(temp_data, d->wdata+y*d->row_scale, sw);
  82.           }
  83.       }
  84.       else
  85.       {
  86.         if (_GrCanBcopyInBlit)
  87.           for (y=0; y<sh; y++)
  88.             bcopy(s->rdata+y*s->row_scale, d->wdata+y*d->row_scale, sw);
  89.         else
  90.           for (y=0; y<sh; y++)
  91.           {
  92.             bcopy(s->rdata+y*s->row_scale, temp_data, sw);
  93.             bcopy(temp_data, d->wdata+y*d->row_scale, sw);
  94.           }
  95.       }
  96.       break;
  97.     case BlitDest:
  98.       break;
  99.     case BlitXor:
  100.       if (reverse)
  101.         for (y=sh-1; y>=0; y--)
  102.           for (x=sw-1; x>=0; x--)
  103.             d->data[x+y*d->row_scale] ^= s->data[x+y*s->row_scale];
  104.       else
  105.         for (y=0; y<sh; y++)
  106.           for (x=0; x<sw; x++)
  107.             d->data[x+y*d->row_scale] ^= s->data[x+y*s->row_scale];
  108.       break;
  109.   }
  110.   free(temp_data);
  111.   delete s;
  112.   delete d;
  113. }
  114.